package com.example.mobile2021606144ywr0401;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


    private TextView tvMainTitle;
    private ImageView ivMainOn;
    private Button btnMainLighOn;
    private Button btnMainLighOff;
    private Button btnMainFan;

    private boolean fanStasus=false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        btnMainLighOn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ivMainOn.setImageResource(R.drawable.on);
            }
        });
        btnMainLighOff.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ivMainOn.setImageResource(R.drawable.off);
            }
        });
        btnMainFan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (fanStasus) {
                    ivMainOn.setImageResource(R.drawable.fanoff);
                    fanStasus = false;
                }else{
                    ivMainOn.setImageResource(R.drawable.fanon);
                    fanStasus=true;
                }
            }
        });
    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        ivMainOn = (ImageView) findViewById(R.id.iv_main_on);
        btnMainLighOn = (Button) findViewById(R.id.btn_main_lighOn);
        btnMainLighOff = (Button) findViewById(R.id.btn_main_lighOff);
        btnMainFan = (Button) findViewById(R.id.btn_main_fan);
    }
}